package com.shigen.demo.atguigu;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * 循环加
 *
 * @author shigenfu
 * @date 2022/5/22 6:58 下午
 */
public class CyclicBarrierDemo {

  public static void main(String[] args) {
    CyclicBarrier cyclicBarrier = new CyclicBarrier(7, ()-> System.out.println("完成收集....."));

    for (int i = 0; i < 7; i++) {
      new Thread(() -> {
        System.out.println(Thread.currentThread().getName() + " 开始.....");

        try {
          cyclicBarrier.await();
        } catch (InterruptedException | BrokenBarrierException e) {
          e.printStackTrace();
        }
      }, String.valueOf(i)).start();
    }

  }

}
